﻿using GJB.MVVMLesson.Bae;
using GJB.MVVMLesson.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace GJB.MVVMLesson.Models
{
    public class MainModel : INotifyPropertyChanged
    {
        //一个值加另外一个值等于第三个值

        private double _value1;

        public double Value1
        {
            get { return _value1; }
            set { _value1 = value;
                (Btn1Command as CommandBase).DoExecuteChanged();
                    }
        }


        public int Value2 { get; set; } = 52;
        private double value3;

        public double Value3
        {
            get { return value3; }
            set { value3 = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value3")); }
        }


        public event PropertyChangedEventHandler? PropertyChanged;

        /// <summary>
        /// hello
        /// </summary>
        public ICommand Btn1Command { get; set; }
        public ICommand Btn2Command { get; set; }

        public void Hello(object obj)
        {
            this.Value3 = this.Value1 + this.Value2;
            WindowManager.ShowDialog("SubWindow");




            ActionManager.Invoke("ShowSubWin");
        }

        public bool CanHello(object obj)
        {
            return this.Value1 != 0;
        }


        public void World(object obj)
        {
            
        }
        public bool CanWorld(object obj)
        {
            return this.Value3 != 0;
        }

        public MainModel()
        {
            Btn1Command = new CommandBase() 
            {
                DoExecute = new Action<object>(Hello),
                DoCanExecute = new Func<object, bool>(CanHello),
            };
            Btn2Command = new CommandBase() {
                DoExecute = new Action<object>(World) ,
                DoCanExecute = new Func<object, bool>(CanWorld) ,
            };
        }
    }
}
